package com.team5.mapper;

import com.team5.entity.News;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface NewsMapper {
    @Select("select * from \"SCOTT\".NEWS where id=#{id}")
    News findById(Integer id);
    @Select("select * from \"SCOTT\".NEWS")
    News[] findAll();

    @Select("select * from \"SCOTT\".NEWS ORDER BY time DESC")
    News[] findAllSortedByDate();

    @Delete("delete from \"SCOTT\".NEWS where id=#{id}")
    int deleteById(Integer id);
    @Delete("delete from \"SCOTT\".NEWS where title=#{title}")
    int deleteByTitle(String title);
    @Delete("delete from \"SCOTT\".NEWS")
    int deleteAll();
    @Insert("insert into \"SCOTT\".NEWS (id, pic, time, title) " +
            "values (#{id}, #{pic}, #{time}, #{title})")
    @SelectKey(statement = "SELECT seq_news.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = int.class)
    int insert(News news);

}
